#include <REGX52.H>
#include <intrins.h>

//模块的data插在p3.3

sbit dht = P3^3;
sbit led = P3^7;

char flag;
char tmp;
char dat[5];

void Delay25ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 45;
	j = 208;
	do
	{
		while (--j);
	} while (--i);
}



void Delay60us()		//@11.0592MHz
{
	unsigned char i;

	i = 25;
	while (--i);
}

void Delay1000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 8;
	j = 1;
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Init_dht(){
	
	dht = 1;
	dht = 0;
	Delay25ms();
	dht = 1;
	Delay60us();
	while(dht);
	while(!dht);
	while(dht);
}

int main(){

	int i,j;
	led = 1;
	Delay1000ms();
	Delay1000ms();
	Init_dht();
	for(i = 0;i < 5;i++){
		for(j = 0; j < 8; j++){
			while(!dht);
			Delay60us();
			if(dht == 1){
				flag = 1;
				while(dht);
			}else{
				flag = 0;
			}
			tmp = tmp << 1;
			tmp |= flag;
		}
		dat[i] = tmp;
	}	
	return 0;
}